<template>
  <div>
    <el-tree :props="tree.treeProps" accordion :data="tree.data" node-key="id" :expand-on-click-node="false"
    >
      <span class="custom-tree-node" slot-scope="{ node, data }">
        <span  @click='nodeClick(node,data)'>{{ node.label }}</span>
        <span v-if="tree.buttons && tree.buttons.length > 0">
          <el-button v-for="(item,index) of tree.buttons" :key='index' :type="item.type || 'text'" @click= 'clickEvent(item,data)' size=mini>{{item.butText}}</el-button>
        </span>
      </span>
    </el-tree>
  </div>
</template>

<script>

  export default {
    name:'tree',
    props:{
      tree:{
        treeProps:null,
        data:null,
        buttons:[],
        nodeClick:null
      }
    },
    methods:{
      // 节点点击事件
      nodeClick(node,data){
        if(this.tree.nodeClick && typeof this.tree.nodeClick == 'function'){
          return this.tree.nodeClick(node,data)
        }
      },
      clickEvent(row,data){
        return row.click(data)
      }
    }
  }

</script>

<style>
</style>
